home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / docs / misc / amigapl.9903.lzh / amigapl.9903 / pci.lzx / Examples / trypci.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-25  |  3.5 KB  |  124 lines

  1. /* program do wyprobowania jak chodza zasoby PCI */
  2. /* resorce i biblioteka                          */
  3. /* jednoczesnie sprawdza czy inkludy sa dobre    */
  4. #include <exec/libraries.h>
  5. #include <clib/exec_protos.h>
  6.  
  7. #include <resources/pcibase.h>
  8. #include <clib/pcires_protos.h>
  9. #include <pragmas/pcires_pragmas.h>
  10.  
  11. #include <libraries/pciexpansionbase.h>
  12. #include <libraries/pciexpansion.h>
  13. #include <clib/pciexpansion_protos.h>
  14. #include <pragmas/pciexpansion_pragmas.h>
  15.  
  16. #include <stdio.h>
  17. #include "embqspan.h"
  18.  
  19.  
  20. extern struct PCIBase * PCIResource = NULL;
  21. extern struct PCIExpBase * PCIExpansionBase = NULL;
  22. char __stdiowin[]="CON:0/10/620/240/Try pci";
  23. char __stdiov37[]="/CLOSE/WAIT";
  24.  
  25.  
  26. char *class_table[256];
  27. char linia[80];
  28. long sizet[5];
  29. unsigned char tmp;
  30.  
  31. unsigned long GetSize(unsigned long base)
  32. {
  33.     return (~base)+1;
  34. }
  35.  
  36.  
  37. struct TagItem tags[] = {
  38.                     /*       {PCIE_VENDORID, 0x5333},
  39.                            {PCIE_BASECLASSCODE, 0x3},     */
  40.                            {TAG_DONE, 0 } };
  41.  
  42. int main(int argc, char * argv[])
  43. {
  44.     ULONG pageid, oldcache;
  45.     struct PCIMapping * map;
  46.     volatile ULONG * p;
  47.     volatile unsigned char *pc;
  48.     struct PCIConfDev * pcidev0 = NULL;
  49.     
  50.     oldcache = CacheControl(0x2011,0xFFFFFFFF);
  51.  
  52.     PCIResource = OpenResource(PCIRESNAME);
  53.     if (PCIResource)
  54.     {
  55.        printf("Success - resources opened !!!!\n");
  56.        PCIExpansionBase = (struct PCIExpBase *)OpenLibrary(PCIEXPANSIONNAME,0L);
  57.        if (PCIExpansionBase)
  58.        {
  59.             printf("Success - library opened !!!!\n");
  60.  
  61.  
  62.             while (pcidev0 = FindPCIDev(pcidev0,tags))
  63.             {
  64.                 printf("%08x\n",pcidev0);
  65.                 printf("Odczyt - %08X\n", GetPCIReg(pcidev0, 0));
  66.             } 
  67.             pcidev0 = AllocPCIDev();
  68.             if (pcidev0 == 0)
  69.                printf("Unable to allocate PCIConfDev\n");
  70.             else
  71.             {
  72.                 AddPCIDev(pcidev0);
  73.                 RemPCIDev(pcidev0);
  74.                 FreePCIDev(pcidev0);
  75.             }
  76.         
  77.             CloseLibrary((struct Library *)PCIExpansionBase);
  78.        }
  79.        else
  80.             printf("Unable to open pciexpansion.library\n");
  81.        printf("Karta w slocie 0 %08X\n", pageid=IntReadCfgReg(0,0));
  82.        printf("Karta w slocie 3 %08X\n", pageid=IntReadCfgReg(3,0));
  83.        map = AllocPCIMapping();
  84.        map->request.address = 0x100157;
  85.        map->request.space = SPACE_MEMORY;
  86.        
  87.        
  88.        pageid = (UBYTE *)&(map->request.space) - (UBYTE *)map;
  89.        printf("Offset %d\n", pageid);
  90.        
  91.        pageid = StorePCIPage(map);
  92.        p = (ULONG *)map->m68_address;
  93.        pageid = RestorePCIPage(map);
  94.        printf("Liczba bledow %ld \n", pageid);
  95.        map->request.address = 0x5000152;
  96.        map->request.space = SPACE_MEMORY;
  97.        map->request.flags |= PCIF_FIFO;
  98.        pageid = ObtainPCIPage(map);
  99.        p = (ULONG *)map->m68_address;
  100.        pageid = ReleasePCIPage(map);
  101.        printf("Liczba bledow %ld \n", pageid);
  102.        map->request.address = 0x3c3;
  103.        map->request.space = SPACE_IO;
  104.        pageid = ObtainPCIPage(map);
  105.        pc = (unsigned char *)map->m68_address;
  106.        printf("odczyt = %d\n", *pc);
  107.        *pc = 1;
  108.        printf("odczyt = %d\n", *pc);
  109.        pc = 0x1000;
  110.        printf("odczyt = %d\n", *pc);
  111.        *pc=10;
  112.        printf("odczyt = %d\n", *pc);
  113.        pageid = ReleasePCIPage(map);
  114.        printf("Liczba bledow %ld \n", pageid);
  115.        FreePCIMapping(map);
  116.  
  117.     }
  118.     else
  119.        printf("Failure - unable to open %s :((((\n", PCIRESNAME);
  120.  
  121.  
  122. }
  123.  
  124.